<template>
	<view class="payment">
		<!-- 导航栏 -->
		<uni-nav-bar left-icon="left" rightText="关闭" title="确认支付" fixed="true" status-bar="true"
			@clickLeft="clickLeft" />
		<view class="pay-main">
			<radio-group>
				<label>
					<view class="pay-item">
						<image class='pay-img' src="../../static/img/zfb.png" mode=""></image>
						<view>
							<view>支付宝支付</view>
							<view class='pay-txt primary-color'>推荐支付宝用户使用</view>
						</view>
						<label class="radio">
							<radio color="red"></radio>
						</label>
					</view>
				</label>

				<label>
					<view class="pay-item">
						<image class='pay-img' src="../../static/img/wxf.png" mode=""></image>
						<view>
							<view>微信支付</view>
							<view class='pay-txt primary-color'>推荐微信用户使用</view>
						</view>
						<label class="radio">
							<radio color="red"></radio>
						</label>
					</view>
				</label>
			</radio-group>
		</view>
		<view class="foot">
			<view class="total">
				<text>合计：</text>
				<text>￥{{data.price}}</text>
			</view>
			<view class="go-pay" @click="goPayment">
				去支付
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState,
		mapMutations
	} from 'vuex';
	import http from '@/common/api/reqeust.js';

	export default {
		data() {
			return {
				data: {
					price: 0,
					goodsName: []
				}
			}
		},
		onLoad(e) {
			this.data = JSON.parse(e.data)
		},
		computed: {
			...mapState({
				orderNumber: state => state.order.orderNumber,
				userInfo: state => state.user.userInfo
			})
		},
		methods: {
			clickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			goPayment() {
				http.request({
					url: '/api/payment',
					method: 'post',
					data: {
						phone: this.userInfo.phone,
						orderId: this.orderNumber, //订单号
						price: this.data.price,
						goodsName: JSON.stringify(this.data.goodsName)
					}
				}).then(res => {
					plus.runtime.openURL(res.paymentUrl);

				}).catch(() => {
					uni.showToast({
						title: '请求失败',
						icon: 'error'
					})
				})
				// uni.requestPayment({
				// 	provider: 'alipay',
				// 	orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
				// 	success: function(res) {
				// 		console.log('success:' + JSON.stringify(res));
				// 	},
				// 	fail: function(err) {
				// 		console.log('fail:' + JSON.stringify(err));
				// 	}
				// });
			}
		},
	}
</script>

<style scoped lang="scss">
	.pay-main {
		.pay-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: $pd20;
			border-bottom: solid 2rpx #ccc;

			.pay-img {
				width: 100rpx;
				height: 100rpx;
			}
		}
	}

	.foot {
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: fixed;
		left: 0;
		bottom: 0;
		height: 100rpx;
		width: 100%;

		.total {
			flex: 1;
			background-color: black;
			line-height: 100rpx;
			color: #fff;
		}

		.go-pay {
			line-height: 100rpx;
			text-align: center;
			padding: 0 $pd20;
			color: #fff;
			background-color: red;
		}
	}
</style>
